﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eis51.CampanyCMS.Model.Bus;
using Eis51.CampanyCMS.FrameWork;

using Eis51.CampanyCMS.Business;

using Eis51.BuildingHtml;

using Eis51.CampanyCMS.Model.BaseInfoMng;
using Eis51.CampanyCMS.Model;
using Eis51.CampanyCMS.Business.BaseInfoMng;
using Eis51.Web.Admin;

namespace Eis51.CampanyCMS.UI.Admin.Baseinfo
{
    public partial class ContactPage : BasePage
    {
       

        

          
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            { 
                ShowData();
            }
        }

        private void ShowData()
        {
            Companyinfo c = null;
            string sql = "select * from CompanyInfo where CREATEBY='{0}' and Licd={1} ";
            sql = string.Format(sql, AppContext.CurrentAdministrator.UserName, AppContext.LCID );
            DataTable dt = CompanyinfoBLL.GetInstance().GetDataTable(sql);
            if (dt != null && dt.Rows.Count>0)
            {
                c = Companyinfo.Dr2Obj(dt.Rows[0], Companyinfo.ColumnNameEnum.DBName);
                if (c != null)
                {
                    UControl.CopyEntityToControl(this.Page.Form, c);
                }
            }
        }


        private bool Save()
        {
            Companyinfo c = new Companyinfo();
            string sql = "select * from CompanyInfo where CREATEBY='{0}' and Licd={1} ";
            sql = string.Format(sql, AppContext.CurrentAdministrator.UserName, AppContext.LCID );
            DataTable dt = CompanyinfoBLL.GetInstance().GetDataTable(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                c = Companyinfo.Dr2Obj(dt.Rows[0], Companyinfo.ColumnNameEnum.DBName);
            }
            
            UControl.CopyControlToEntity(this.Page.Form, c);
           
            if (dt != null && dt.Rows.Count > 0)
            {
                CompanyinfoBLL.GetInstance().Update(c);
            }
            else
            {
                c.Licd = AppContext.LCID ;
                c.Createby = AppContext.CurrentAdministrator.UserName;
                c.Createdate = DateTime.Now;
                CompanyinfoBLL.GetInstance().Insert(c);
            }

           //  BuildPageHtml.BuildPage(c,"~/shop/xml/contact.xml" );
 
            return true;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Save();
            BaseTools.ShowMessage(this.Page, "提交成功！");
        }

        protected void btnReturn_Click(object sender, EventArgs e)
        {

        }



    }
}
